#include "../array/array.h"
#include "semaphores.h"
#include <string.h>
#include <stdio.h>

Array* semaphores=NULL;
Array* names=NULL;


void add_semephore(char* name, sem_t* sem){
	if(!semaphores){
		semaphores=newArray();
		names=newArray();
	}
	char* nam=malloc(strlen(name)+1);
	strcpy(nam,name);
	add(semaphores, sem);
	add(names,nam);
}


void close_semaphores(){
	if(semaphores){
		int i;
		for(i=0;i<semaphores->count;i++){
			sem_close(semaphores->array[i]);
			sem_destroy(semaphores->array[i]);
			sem_unlink(names->array[i]);
			free(names->array[i]);
		}
		deleteArray(semaphores);
		deleteArray(names);
	}
}
